import 'package:flutter/material.dart';
import 'package:codersun/pages/good_detail_page.dart';
import 'package:codersun/pages/search_page.dart';

class HomePage extends StatefulWidget {
  final Map<String, dynamic> arguments;
  HomePage({Key key, this.arguments}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    List<PageModel> pages = [
      PageModel(
        title: 'draggablePage',
        subtitle: '拖拽',
        click: () {
          Navigator.pushNamed(context, '/draggablePage');
        },
      ),
      PageModel(
        title: 'filterPage',
        subtitle: '模糊滤镜',
        click: () {
          Navigator.pushNamed(context, '/filterPage');
        },
      ),
      PageModel(
        title: 'clipPathPage',
        subtitle: '贝塞尔曲线',
        click: () {
          Navigator.pushNamed(context, '/clipPathPage');
        },
      ),
      PageModel(
        title: 'flutterEasyrefreshPage',
        subtitle: '上下拉刷新',
        click: () {
          Navigator.pushNamed(context, '/flutterEasyrefreshPage');
        },
      ),
      PageModel(
        title: 'flutterToastPage',
        subtitle: 'Toast',
        click: () {
          Navigator.pushNamed(context, '/flutterToastPage');
        },
      ),
      PageModel(
        title: 'listViewRefreshIndicatorPage',
        subtitle: '上下拉刷新',
        click: () {
          Navigator.pushNamed(context, '/listViewRefreshIndicatorPage');
        },
      ),
      PageModel(
        title: 'listViewPage',
        subtitle: '滚动监听',
        click: () {
          Navigator.pushNamed(context, '/listViewPage');
        },
      ),
      PageModel(
        title: 'flutterSwiperPage',
        subtitle: '轮播',
        click: () {
          Navigator.pushNamed(context, '/flutterSwiperPage');
        },
      ),
      PageModel(
        title: 'imagePage',
        click: () {
          Navigator.pushNamed(context, '/imagePage');
        },
      ),
      PageModel(
        title: 'asyncAwaitPage',
        click: () {
          Navigator.pushNamed(context, '/asyncAwaitPage');
        },
      ),
      PageModel(
        title: 'someChowdersPage',
        click: () {
          Navigator.pushNamed(context, '/someChowdersPage');
        },
      ),
      PageModel(
        title: 'isolatePage',
        click: () {
          Navigator.pushNamed(context, '/isolatePage');
        },
      ),
      PageModel(
        title: 'animationPage',
        click: () {
          Navigator.pushNamed(context, '/animationPage');
        },
      ),
      PageModel(
        title: 'rxDartPage',
        click: () {
          Navigator.pushNamed(context, '/rxDartPage');
        },
      ),
      PageModel(
        title: 'blocPage',
        click: () {
          Navigator.pushNamed(context, '/blocPage');
        },
      ),
      PageModel(
        title: 'streamPage',
        click: () {
          Navigator.pushNamed(context, '/streamPage');
        },
      ),
      PageModel(
        title: 'sliverPage',
        click: () {
          Navigator.pushNamed(context, '/sliverPage');
        },
      ),
      PageModel(
        title: 'stateManagementPage',
        click: () {
          Navigator.pushNamed(context, '/stateManagementPage');
        },
      ),
      PageModel(
        title: 'stepperPage',
        click: () {
          Navigator.pushNamed(context, '/stepperPage');
        },
      ),
      PageModel(
        title: 'librariesPage',
        click: () {
          Navigator.pushNamed(context, '/librariesPage');
        },
      ),
      PageModel(
        title: 'genericPage',
        click: () {
          Navigator.pushNamed(context, '/genericPage');
        },
      ),
      PageModel(
        title: 'dataTablePage',
        click: () {
          Navigator.pushNamed(context, '/dataTablePage');
        },
      ),
      PageModel(
        title: 'chipPage',
        click: () {
          Navigator.pushNamed(context, '/chipPage');
        },
      ),
      PageModel(
        title: 'dialogPage',
        click: () {
          Navigator.pushNamed(context, '/dialogPage');
        },
      ),
      PageModel(
        title: 'dateTimePage',
        click: () {
          Navigator.pushNamed(context, '/dateTimePage');
        },
      ),
      PageModel(
        title: 'httpAndModelPage',
        click: () {
          Navigator.pushNamed(context, '/httpAndModelPage');
        },
      ),
      PageModel(
        title: 'classesPage',
        click: () {
          Navigator.pushNamed(context, '/classesPage');
        },
      ),
      PageModel(
        title: 'functionPage',
        click: () {
          Navigator.pushNamed(context, '/functionPage');
        },
      ),
      PageModel(
        title: 'checkBoxAndRadioAndSwitchPage',
        click: () {
          Navigator.pushNamed(context, '/checkBoxAndRadioAndSwitchPage');
        },
      ),
      PageModel(
        title: 'textFieldPage',
        click: () {
          Navigator.pushNamed(context, '/textFieldPage');
        },
      ),
      PageModel(
        title: 'buttonsPage',
        click: () {
          Navigator.pushNamed(context, '/buttonsPage', arguments: {});
        },
      ),
      PageModel(
        title: 'customAppBarAnotherMethodPage',
        click: () {
          Navigator.pushNamed(context, '/customAppBarAnotherMethodPage', arguments: {});
        },
      ),
      PageModel(
        title: 'customAppBarPage',
        click: () {
          Navigator.pushNamed(context, '/customAppBarPage', arguments: {});
        },
      ),
      PageModel(
        title: '命名路由 跳转',
        click: () {
          callback() {
            print('命名路由 跳转 跳转后回调');
          }

          Navigator.pushNamed(context, '/goodDetailPage', arguments: {
            GoodDetailPage.goodIdKey: '123456',
            GoodDetailPage.callbackKey: callback,
          });
        },
      ),
      PageModel(
        title: '普通路由 跳转',
        click: () {
          final route = MaterialPageRoute(builder: (context) => Search(arguments: {'keyword': 'MacBook Pro 16-inch'}));
          Navigator.of(context).push(route);
        },
      ),
    ];

    return Scaffold(
      appBar: AppBar(title: Text('HomePage')),
      body: ListView.builder(
        itemCount: pages.length,
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            onTap: () {
              pages[index].click();
            },
            child: Container(
              padding: EdgeInsets.only(left: 15.0, right: 15.0),
              alignment: Alignment.centerLeft,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: (() {
                  List<Widget> list = List();
                  list.add(SizedBox(height: 8.0));
                  list.add(Text(pages[index].title));

                  final subtitle = pages[index].subtitle;
                  if (subtitle != null) {
                    list.add(SizedBox(height: 3.0));
                    list.add(Text(
                      subtitle,
                      style: TextStyle(color: Colors.grey, fontSize: 12.0),
                    ));
                  }

                  list.add(SizedBox(height: 8.0));
                  return list;
                })(),
              ),
              decoration: BoxDecoration(
                border: Border(bottom: BorderSide(width: 0.5, color: Color(0xffe5e5e5))),
              ),
            ),
          );
        },
      ),
    );
  }
}

class PageModel {
  final String title;
  final String subtitle;
  final VoidCallback click;

  PageModel({@required this.title, this.subtitle, this.click});
}
